package com.fenger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fenger.contast.SysConstast;
import com.fenger.domain.Reply;
import com.fenger.mapper.ReplyMapper;
import com.fenger.service.ReplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fenger.utils.DataGirdView;
import com.fenger.vo.ReplyVo;
import com.fenger.vo.TopicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 方
 * @since 2019-04-29
 */
@Service
public class ReplyServiceImpl extends ServiceImpl<ReplyMapper, Reply> implements ReplyService {

    @Autowired
    ReplyMapper replyMapper;
    @Override
    public DataGirdView queryReplyByTopicid(TopicVo topicVo) {

//        for (int i = 50; i < 55; i++) {
//            Reply reply = new Reply();
//            reply.setTopicid(i);
//            reply.setAuthor("小明"+i);
//            reply.setContent("楼上+"+i);
//            reply.setCreatedate(new Date());
//            this.replyMapper.insert(reply);
//        }

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("topicid",topicVo.getTopicid());
        List<Reply> list = this.replyMapper.selectList(wrapper);
        return new DataGirdView(SysConstast.SUCCESS_CODE,SysConstast.SUCCESS_MSG,100L,list);

    }



    @Override
    public DataGirdView insertReply(ReplyVo replyVo) {
        try {
            replyVo.setCreatedate(new Date());
            replyMapper.insert(replyVo);
            return new DataGirdView(SysConstast.ADD_SUCCESS_CODE,SysConstast.ADD_SUCCESS_MSG,0L,null);
        } catch (Exception e) {
            e.printStackTrace();
            return new DataGirdView(SysConstast.ADD_ERROR_CODE,SysConstast.ADD_ERROR_MSG,0L,null);
        }
    }
}
